package com.pricl.api.util;

import java.security.MessageDigest;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.pricl.biz.admin.entity.AdminUser;
import com.pricl.biz.admin.entity.criteria.AdminUserCriteria;
import com.pricl.biz.admin.entity.criteria.AdminUserThirdLoginCriteria;
import com.pricl.biz.admin.service.AdminUserService;
import com.pricl.frame.core.E;
import com.pricl.frame.token.jwt.CertifyConstant;

/**
 * adminUser工具类
 * @author yangwendong
 * @since 2017-6-16
 */
public enum AdminUserUtils {
	
	INSTANCE;
	
	/**
	 * 判断传入的用户表示是手机还是uid
	 * @param uniqueString
	 * @return 1为手机号，2为uid 3为游客
	 */
	public int judgeUserPhoneOrUid(String uniqueString) {
		 Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$");
		 Matcher m = p.matcher(uniqueString);
		 if (CertifyConstant.NO_BODY.equals(uniqueString)) {
			 return 3;
		 }
		 if (m.matches()) {
			 return 1;
		 } else {
			 return 2;
		 }
	}
	
	/**
	 * 转Long
	 */
	public <T> Long parseObjectToLong(T t) {
		String str = String.valueOf(t);
		if (StringUtils.isNumeric(str)) {
			return Long.valueOf(String.valueOf(str));
		}
		return 0L;
	}
	
	/**
	 * 获取随机数，可以做盐或者token
	 */
	public String getRandom() {
		return UUID.randomUUID().toString();
	}
	
	/**
	 * md5加密
	 * @param s
	 * @return
	 */
	public String MD5(String s) {  
        char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};         
        try {  
            byte[] btInput = s.getBytes();  
            // 获得MD5摘要算法的 MessageDigest 对象  
            MessageDigest mdInst = MessageDigest.getInstance("MD5");  
            // 使用指定的字节更新摘要  
            mdInst.update(btInput);  
            // 获得密文  
            byte[] md = mdInst.digest();  
            // 把密文转换成十六进制的字符串形式  
            int j = md.length;  
            char str[] = new char[j * 2];  
            int k = 0;  
            for (int i = 0; i < j; i++) {  
                byte byte0 = md[i];  
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];  
                str[k++] = hexDigits[byte0 & 0xf];  
            }  
            return new String(str);  
        } catch (Exception e) {  
            e.printStackTrace();  
            return null;  
        }  
    }  
	
	public static void main(String[] args) {
		//System.out.println(INSTANCE.MD5("111111"+"e10adc3949ba59abbe56e057f20f883e"));
		
		System.out.println(INSTANCE.parseObjectToLong("1r"));
	}
}
